//
//  HomeEqumentOneCellCollectionViewCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/6.
//  Copyright © 2020 tym. All rights reserved.
//

#import "HomeEqumentOneCell.h"
#import "UIimage+Extends.h"
#import "UIButton+ImageTitleSpacing.h"
#import "UIImageView+YPImage.h"
#import "UIButton+Gradient.h"

@interface HomeEqumentOneCell ()

@property(nonatomic,weak) IBOutlet UIView *conView;
@property(nonatomic,weak) IBOutlet UIImageView *imageView;
@property(nonatomic,weak) IBOutlet UILabel *nameLab;
@property(nonatomic,weak)IBOutlet UILabel *roomLab;
@property(nonatomic,weak)IBOutlet UILabel *lineLab;

@property(nonatomic,weak) IBOutlet UIButton *elecBtn;
@property(nonatomic,weak) IBOutlet UIButton *wifiBtn;
@property(nonatomic,weak) IBOutlet UIButton *blueBtn;
@property(nonatomic,weak) IBOutlet UIButton *stateBtn;
 
@end

@implementation HomeEqumentOneCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.conView.layer.cornerRadius = 10;
    self.contentView.layer.masksToBounds = YES;
    [self.contentView sizeToFit];
}

-(void)setEqumentModel:(EquipmentModel *)equmentModel{
    _equmentModel = equmentModel;
    _nameLab.text = equmentModel.equipmentName;
    _roomLab.text = equmentModel.roomName;
    [_imageView yp_setImageUlr:[equmentModel getEquipmentImage]];
    
    if(_equmentModel.online){
        [self.elecBtn setImage:[UIImage imageNamed:[self elecBtnImageZaiXian:_equmentModel.electricQuantity?_equmentModel.electricQuantity:@(0)]] forState:UIControlStateNormal];
        [self.wifiBtn setImage:[UIImage imageNamed:[self wiftBtnImageZaiXian:_equmentModel.wifiStrength]] forState:UIControlStateNormal];
        [self.blueBtn setImage:[UIImage imageNamed:@"icon_equipment_nor1"] forState:UIControlStateNormal];
        //[self.blueBtn setImage:[UIImage imageNamed:@"icon_equipment8"] forState:UIControlStateNormal];
       //[self.blueBtn setTitleColor:rgba(54, 53, 70) forState:UIControlStateNormal];
        [self.blueBtn setTitleColor:rgba(155, 155, 155) forState:UIControlStateNormal];
        [self.elecBtn setTitleColor:rgba(54, 53, 70) forState:UIControlStateNormal];
        [self.wifiBtn setTitleColor:rgba(54, 53, 70) forState:UIControlStateNormal];
        [self.stateBtn setTitleColor:rgba(155, 155, 155) forState:UIControlStateNormal];
        [self.stateBtn setTitle:@"唤醒" forState:UIControlStateNormal];
        [self.stateBtn setImage:[UIImage imageNamed:@"icon_equipment7"] forState:UIControlStateNormal];
        _lineLab.text = @"•在线";
        _lineLab.textColor = rgba(72, 132, 255);
    }else{
        [self.stateBtn setImage:[UIImage imageNamed:@"icon_equipment71"] forState:UIControlStateNormal];
        [self.stateBtn setTitle:@"休眠" forState:UIControlStateNormal];
        [self.stateBtn setTitleColor:rgba(54, 53, 70) forState:UIControlStateNormal];
        [self.blueBtn setImage:[UIImage imageNamed:@"icon_equipment_nor1"] forState:UIControlStateNormal];
        [self.wifiBtn setImage:[UIImage imageNamed:[self wiftBtnImageLixian:0]] forState:UIControlStateNormal];
        [self.elecBtn setImage:[UIImage imageNamed:[self elecBtnImageLiXian:_equmentModel.electricQuantity?_equmentModel.electricQuantity:@(0)]] forState:UIControlStateNormal];
        [self.blueBtn setTitleColor:rgba(155, 155, 155) forState:UIControlStateNormal];
        [self.elecBtn setTitleColor:rgba(155, 155, 155) forState:UIControlStateNormal];
        [self.wifiBtn setTitleColor:rgba(155, 155, 155) forState:UIControlStateNormal];
        _lineLab.text = @"•离线";
        _lineLab.textColor = rgba(207, 213, 229);
    }
    
    [self.elecBtn setTitle:[NSString stringWithFormat:@"%@%%",_equmentModel.electricQuantity?_equmentModel.electricQuantity:@(0)] forState:UIControlStateNormal];
    [self.elecBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3 ];
    [self.wifiBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3 ];
    if(_equmentModel.timeMillisecond){
        
        //[self.stateBtn.titleLabel setTextColor:rgba(54, 53, 70)];
    }else{
        
        //[self.stateBtn.titleLabel setTextColor:rgba(97, 97, 97)];
    }
    
    [self.blueBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3 ];
}

-(NSString*)elecBtnImageZaiXian:(NSNumber*)elecValue{
    if (elecValue == nil || [elecValue intValue] <= 20) {
        return @"icon_equipment903";
    }else if([elecValue integerValue] <= 40 ){
        return @"icon_equipment99";
    }else if([elecValue intValue] <= 70){
        return @"icon_equipment9";
    }
    return @"icon_equipment92";
}

-(NSString*)elecBtnImageLiXian:(NSNumber*)elecValue{
    if (elecValue == nil || [elecValue intValue] <= 20) {
        return @"icon_equipment903";
    }else if([elecValue integerValue] <= 40 ){
        return @"icon_battery3";
    }else if([elecValue intValue] <= 70){
        return @"icon_battery6";
    }
    return @"icon_battery9";
}

-(NSString*)wiftBtnImageZaiXian:(NSInteger)wifiValue{
    if (!wifiValue) {
        return @"icon_equipment103";
    }else if(wifiValue < 5){
       return @"icon_equipment102";
    }else if(wifiValue < 20){
         return @"icon_equipment104";
    }else if(wifiValue < 30){
        return @"icon_equipment100";
    }else if(wifiValue < 50){
        return @"icon_equipment101";
    }
    return @"icon_equipment11";
}

-(NSString*)wiftBtnImageLixian:(NSInteger)wifiValue{
    if (!wifiValue) {
        return @"icon_equipment103";
    }else if(wifiValue < 5){
       return @"icon_equipment102";
    }else if(wifiValue < 20){
         return @"icon_equipment104";
    }else if(wifiValue < 30){
        return @"icon_equipment100";
    }else if(wifiValue < 50){
        return @"icon_equipment101";
    }
    return @"icon_equipment11";
}

+(CGSize)cellHeight{
    return CGSizeMake(ScreenWidth-30, 147);
}

+(NSString*)identifiter{
    return @"HomeEqumentOneCell";
}

@end
